Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // Importers should always start with this |
||
13 | PassmanImporter.passmanJson.readFile = function (file_data) { |
||
14 | return new C_Promise(function(){ |
||
15 | var parsed_json = PassmanImporter.readJson(file_data); |
||
16 | var credential_list = []; |
||
17 | for (var i = 0; i < parsed_json.length; i++) { |
||
18 | var item = parsed_json[i]; |
||
19 | var _credential = PassmanImporter.newCredential(); |
||
20 | _credential.label = item.label; |
||
21 | _credential.username = item.account; |
||
22 | _credential.password = item.password; |
||
23 | _credential.email = item.email; |
||
24 | _credential.url = item.url; |
||
25 | _credential.tags = item.tags; |
||
26 | _credential.description = item.description; |
||
27 | //Check for custom fields |
||
28 | if (item.hasOwnProperty('customFields')) { |
||
29 | //Check for otp |
||
30 | if (item.customFields.length > 0) { |
||
31 | for (var cf = 0; cf < item.customFields.length; cf++) { |
||
32 | _credential.custom_fields.push( |
||
33 | { |
||
34 | 'label': item.customFields[cf].label, |
||
35 | 'value': item.customFields[cf].value, |
||
36 | 'secret': (item.customFields[cf].clicktoshow == '1') |
||
37 | } |
||
38 | ) |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | if (item.hasOwnProperty('otpsecret')) { |
||
43 | if (item.otpsecret) { |
||
44 | _credential.otp = { |
||
45 | 'issuer': item.otpsecret.issuer, |
||
46 | 'label': item.otpsecret.label, |
||
47 | 'qr_uri': { |
||
48 | 'image': item.otpsecret.qrCode, |
||
49 | 'qrData': '' |
||
50 | }, |
||
51 | 'secret': item.otpsecret.secret, |
||
52 | 'type': item.otpsecret.type |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | if(_credential.label){ |
||
57 | credential_list.push(_credential); |
||
58 | } |
||
59 | var progress = { |
||
60 | percent: i/parsed_json.length*100, |
||
61 | loaded: i, |
||
62 | total: parsed_json.length |
||
63 | }; |
||
64 | |||
65 | this.call_progress(progress); |
||
66 | } |
||
67 | this.call_then(credential_list); |
||
68 | }); |
||
69 | }; |
||
70 | })(window, $, PassmanImporter); |
||
71 |